import type { App } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'
import { createRouterGuard } from './guard'
// import routes from 'virtual:generated-pages'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('../views/login/MechanismLogin.vue'),
    name: 'jgLogin',
    meta: { hidden: true },
  },
  {
    path: '/userLogin',
    component: () => import('../views/login/UserLogin.vue'),
    name: 'userLogin',
    meta: { hidden: true },
  },
  {
    path: '/home',
    component: Layout,
    meta: { hidden: true },
    redirect: '/',
    children: [
      // {
      //   path: '/',
      //   component: () => import('../views/login/MechanismLogin.vue'),
      //   name: 'login',
      // },
      {
        path: '/jgPersonnelInfo',
        component: () => import('../views/mechanism/JgPersonnelInfo.vue'),
        name: 'jgPersonnelInfo',
      },
      {
        path: '/baseInfoMaintain',
        component: () => import('../views/user/BaseInfoMaintain.vue'),
        name: 'baseInfoMaintain',
      },
      {
        path: '/mechanismInfo',
        component: () => import('../views/user/MechanismInfo.vue'),
        name: 'mechanismInfo',
      },
      {
        path: '/personnelInfo',
        component: () => import('../views/user/PersonnelInfo.vue'),
        name: 'personnelInfo',
      },
      {
        path: '/vehicleInfo',
        component: () => import('../views/user/VehicleInfo.vue'),
        name: 'vehicleInfo',
      },
      {
        path: '/videoInfo',
        component: () => import('../views/user/VideoInfo.vue'),
        name: 'videoInfo',
      },
    ],
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "dashboard" */ '../views/error/index.vue'),
    name: 'error',
    meta: {
      title: 'error',
      icon: '#icondashboard',
      affix: true,
    },
  },
]

// export const router = createRouter({
//   // history: createWebHistory(),
//   routes,
// })

export const router = createRouter({
  /** 打包配置二级路径 */
  // history: createWebHashHistory('readiness'),
  history: createWebHashHistory(),
  routes,
})

export async function setupRouter(app: App) {
  app.use(router)
  createRouterGuard(router)
  await router.isReady()
}
